<template>
  <div id="app">
    <nav>
      <Topbar :key="topbarkey"></Topbar>
      <Header></Header>
      <router-view @updateKey="updateKeyFn" />
      <Footer></Footer>
      <Login v-show="isShowLoginModal"></Login>
      <transition name="slide">
        <Toast v-show="isShowToast"></Toast>
      </transition>
    </nav>
  </div>
</template>

<script>
import Topbar from "./components/Topbar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";
import { JingPinAPI, ReMenAPI } from "@/require/api.js";
import "@/assets/css/public.less";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: 0,
    };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  // 异步代码同步话（进到页面就要加载完毕）
  async created() {
    console.log("环境变量为:", process.env.VUE_APP_BASE_URL);
    console.log("环境变量为:", process.env.VUE_APP_MY_NAME);
    console.log("app-created");
    let res = await JingPinAPI();
    console.log("精品", res);
    let res2 = await ReMenAPI();
    console.log("热门", res2);
  },
  methods: {
    updateKeyFn() {
      console.log("父收到了");
      this.topbarkey++;
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        console.log("地址发生改变了", newVal, oldVal);
        if (oldVal != "/") {
          this.topbarkey++;
        }
      },
    },
  },
};
</script>

<style lang="less" scoped>
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
